<?php
namespace app\admin\controller;
use think\Db;

class Push
{
	public function __construct(){
		Admin_auth();
	}
	
    public function index()
    {
        if(request()->isPost()) {
            $post = request()->post();
            $list = Db::table($post['type'])->select();
            $array = [];
            foreach ($list as $k => $v){
                $array[] = md5($v['id']);
                insert_message($post['type'],$v['id'],'系统消息',$post['message'],0);
            }
            push($array,json_encode(['type'=>0,'message'=>$post['message'],'parameters'=>'']),$post['type']);
            $post['time'] = time();
            Db::table('push')->insert($post);
        }
        $tab = request()->get('tab');
        $pages = pages('push','',input('get.page'));
        $list = Db::table('push')->limit($pages['limit'])->order('time desc')->select();
        return view('',['list' => $list,'tab' => $tab,'pages' => $pages['pages']]);
    }

}
